<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>注册</title>
    <link rel="stylesheet" href="../static/common/plugs/layui/css/layui.css"/>
    <link rel="stylesheet" href="../static/register/userlogo.css"/>
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js"></script>
    <style type="text/css">
        .login {
            height: 402px;
            width: 260px;
            padding: 20px;
            background-color: rgba(0, 0, 0, 0.5);
            border-radius: 4px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -320px 0 0 -150px;
            z-index: 99;
        }
    </style>
</head>
<body>

<img width="100%" height="100%" class="video-player" src="../static/common/images/login1.jpeg">
<div class="video_mask"></div>
<div class="login">
    <h1>注册</h1>
    <form id="form" enctype="multipart/form-data" class="layui-form layui-form-pane my-two-form">
    <div class="layui-form-item">
        <input class="layui-input" id="name" name="name" placeholder="用户名" lay-verify="required" type="text" autocomplete="off">
    </div>
    <div class="layui-form-item">
        <input class="layui-input" id="code" name="code" placeholder="账号：请输入邮箱" lay-verify="required" type="text" autocomplete="off">
    </div>
    <div class="layui-form-item">
        <input class="layui-input" id="upassword" name="upassword" placeholder="密码" lay-verify="required" type="password" autocomplete="off">
    </div>
    <div class="layui-form-item">
        <img id="verify" onclick="refreshVerify()" th:src="@{/common/verifyCode/getVerifyCode}">
        <button onclick="refreshVerify()" type="button" class="layui-btn">刷新</button>
    </div>
    <div class="layui-form-item">
        <button style="margin-left:0%;width: 200px" class="layui-btn" lay-filter="add" lay-submit>注册</button>
    </div>
    </form>
</div>
<script type="text/javascript" src="../static/common/plugs/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer','upload', 'jquery','laydate', 'admin'],function (){
        var form = layui.form,
            $ = layui.jquery,
            laydate = layui.laydate,
            upload = layui.upload,
            layer = layui.layer;

        laydate.render({
            elem: '#bornDate',
            type: 'datetime',
            trigger: 'click'
        });
        //监听提交
        form.on('submit(add)',function (data){
            console.log(data.field);
            var formData = new FormData($("#form")[0]);
            // if ()
            $.ajax({
                url: "/user/register",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function (){
                    //返回的参数item，即为当前的input DOM对象
                    index = layer.load(1,{shade: [0.3,'grey']});
                },
                success: function (res){
                    layer.close(index);
                    if(res.success == true){
                        layer.msg(res.msg,{icon:1, time: 1500},function (){
                           refreshParent();
                        });
                    }else {
                        layer.msg(res.msg,{icon:2, time 1500});
                    }
                },
                error: function (res){
                    layer.msg(res,{icon: 2, time: 1500});
                },
                complete: function (){

                }
            });
        });
    });
    function refreshVerify(){
        var myData = new Date();
        var times = myData.getTime();
        $("#verify").attr("src", "/common/verifyCode/getVerifyCode?times=" + times);
    }
</script>
</body>
</html>